package com.ja.openchat.viewmodels;

import android.app.Application;

import androidx.annotation.NonNull;

import com.ja.openchat.ui.contact.GroupListChildFragment;
import com.zy.openchat.core.manager.TgEvent;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import me.goldze.mvvmhabit.base.BaseViewModel;


public class GroupListChildViewModel extends BaseViewModel {

    private GroupListChildFragment groupListFragment;

    public GroupListChildViewModel(@NonNull Application application) {
        super(application);
    }





    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onTgEvent(final TgEvent tg_event) {
        switch (tg_event.event) {
            case EUser_Td_Contact_Photo_Ok:
            case EUser_Td_Chat_Changed:
                if(groupListFragment != null && groupListFragment.groupListAdapter != null)
                groupListFragment.groupListAdapter.notifyDataSetChanged();
                break;
            case EUser_Td_Chat_List_Changed:
                groupListFragment.stopRefreshTimer();
                groupListFragment.startRefreshTimer();
                break;
        }
    }

    public void setFragment(GroupListChildFragment groupListFragment) {
        this.groupListFragment = groupListFragment;
    }
}
